﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using RBS.Common;

namespace RBS.Web.Hotel.tools
{
    /// <summary>
    /// hotelAjax 的摘要说明
    /// </summary>
    public class hotelAjax : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {  //取得处事类型
            string action = RBSRequest.GetQueryString("action");
            switch (action)
            {
                case "email_validate": //验证扩展字段是否重复
                    email_validate(context);
                    break;
                case "lave_validate": //验证扩展字段是否重复
                    lave_validate(context);
                    break; 
            }
        }

        private void lave_validate(HttpContext context)
        {
            string num = RBSRequest.GetString("param");
            string lave = RBSRequest.GetString("lave");
            if (string.IsNullOrEmpty(num))
            {
                context.Response.Write("{ \"info\":\"请输入优惠券数量\", \"status\":\"n\" }");
                return;
            }
            if (num=="0")
            {
                context.Response.Write("{ \"info\":\"赠送数量必须大于等于一张\", \"status\":\"n\" }");
                return;
            }
            var l = int.Parse(lave) - int.Parse(num);
            if (int.Parse(lave) - int.Parse(num)<0)
            {
                context.Response.Write("{ \"info\":\"赠送数量不能大于剩余优惠卷！\", \"status\":\"n\" }");
                return;
            }
            context.Response.Write("{ \"info\":\"优惠卷还剩"+l+"张\", \"status\":\"y\" }");
            return;
        } 
        private void email_validate(HttpContext context)
        {
            string email = RBSRequest.GetString("param");
            if (string.IsNullOrEmpty(email))
            {
                context.Response.Write("{ \"info\":\"请输入手机号码\", \"status\":\"n\" }");
                return;
            }
           var bll = new Core.BLL.Hotel.H_Hotel_Users();
            if (bll.Exists(email))
            {
                context.Response.Write("{ \"info\":\"手机号码已被占用，请更换！\", \"status\":\"n\" }");
                return;
            }
            context.Response.Write("{ \"info\":\"手机号码可使用\", \"status\":\"y\" }");
            return;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}